package one.stand.enums;

import com.google.common.collect.Maps;

import java.util.Map;
import java.util.function.Function;

/**
 * @author Administrator
 */
public class EnumUtil {

    public static <T extends Enum<T>, K> Map<K, T> getEnumMap(T[] values, Function<T, K> keyFun) {
        Map<K, T> map = Maps.newHashMapWithExpectedSize(values.length);
        K key;
        for (T tEnum : values) {
            key = keyFun.apply(tEnum);
            map.put(key, tEnum);
        }
        return map;
    }
}
